﻿#ifndef MYTREEVIEW_H
#define MYTREEVIEW_H

#include <QTreeView>
#include <QMenu>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QQueue>
#include "companyservice.h"
#include "userservice.h"

class MyTreeView : public QTreeView
{
    Q_OBJECT
public:

    explicit MyTreeView(QWidget *parent = nullptr);

    void setCategoryType(Company::CategoryType categoryType);

    void initWithCategory(QString category, QString rootName, QString firstCategoryName);

    void initWithCategory(QString category, QString defaultCategory);

    void loadCategory(QStandardItem *parent, QStandardItem *curItem, QQueue<QVariant> *categoryQueue);

    QString saveCategory(QStandardItem *curItem);

    virtual void onAddActionTriggered();

    void updateCategory();

    void doDeleteItem();

    bool checkItem(QStandardItem *treeItem, QString label);

    void doEditItem(QString newCategory);

    QString selectedPrimaryDirectory();

    QString selectedSecondaryDirectory();

    QStringList primaryDirectoryList();

    QList<QStringList> secondaryDirectoryList();
signals:

public slots:
    void showMenu(const QPoint point);

    void addItem();

    void deleteItem();

    void editItem();

    QStandardItem* selectedItem();

private:
    QMenu menu;
    QStandardItemModel model;
    QStandardItem *rootItem;
    QStandardItem *currentItem;

    Company::CategoryType categoryType;

    CompanyService companyService;
    UserService userService;
};

#endif // MYTREEVIEW_H
